package com.mc.moring.main.personal.adapter;


import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mc.moring.R;
import com.mc.moring.bean.BankAccountListBean;
import com.mc.moring.util.ToastUtils;

import java.util.List;

public class BankAccountAdapter extends BaseQuickAdapter<BankAccountListBean.DataBean.AccountsBean, BaseViewHolder> {

    BankListener bankListener;

    public BankAccountAdapter(@Nullable List<BankAccountListBean.DataBean.AccountsBean> data) {
        super(R.layout.item_bank_account, data);
    }

    public void setBankAccountListener(BankListener mBankListener) {
        this.bankListener = mBankListener;
    }


    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, BankAccountListBean.DataBean.AccountsBean bean) {
        baseViewHolder.addOnClickListener(R.id.tv_eliminar);
        TextView tv_bank_num = baseViewHolder.getView(R.id.tv_bank_num);
        TextView tv_bank_name = baseViewHolder.getView(R.id.tv_bank_name);
        TextView tv_eliminar = baseViewHolder.getView(R.id.tv_eliminar);
        tv_bank_name.setText(bean.getBankName());
        tv_bank_num.setText("********" + bean.getLast4());
        if (getData().size() == 1) {
            tv_eliminar.setVisibility(View.GONE);
        } else {
            tv_eliminar.setVisibility(View.VISIBLE);
        }

        tv_eliminar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bean.getPayStatus() =="-1" || bean.getPayStatus() == "-2" || bean.getPayStatus() == "4001") {
                    ToastUtils.showShort(mContext, "¡Eliminación fallida! Esta cuenta se utiliza para el procesamiento de desembolsos");
                    return;
                }
                bankListener.deleteBankAccount(bean.getAccountId());
            }
        });
    }

    public interface BankListener {
        void deleteBankAccount(String accountId);

    }

}
